fix(NODE-7411): closeCheckedOutConnections iterates all servers and fixes test regression#4917
Open
sarthaksoni25 wants to merge 3 commits intomongodb:mainfrom
Open
fix(NODE-7411): closeCheckedOutConnections iterates all servers and fixes test regression#4917sarthaksoni25 wants to merge 3 commits intomongodb:mainfrom
sarthaksoni25 wants to merge 3 commits intomongodb:mainfrom
Conversation
The method had a premature 'return' inside the for loop, which caused it to only close connections on the first server and exit immediately. This fix removes the return statement so all servers have their checked-out connections closed when MongoClient.close() is called. This bug would affect multi-server topologies (replica sets, sharded clusters) where only the first server's connections would be properly closed.
…deployments - Remove 'single' topology restriction from metadata to support replicaset/sharded - Use readPreference: 'secondaryPreferred' to exercise connections to secondaries - Switch from insert to find operations to validate reads against secondaries
86aa05b to
cbf90e8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug in
closeCheckedOutConnections()intopology.tswhere a prematurereturncaused cleanup to stop after the first server, skipping checked-out connections on remaining servers in multi-server topologies such as replica sets and sharded clusters.Fixes the
ConnectionCheckedInEventtest inconnection_pool.test.ts. The previous test usedreadPreference: 'secondaryPreferred', which could routefindoperations to secondaries where no failpoint was configured. As a result, the finds could complete beforeclient.close()was called, making the test ineffective for validating in-flight connection cleanup.Adds a dedicated
closeCheckedOutConnectionstest inclient_close.test.tsto verify the CMAP requirement that, for in-flight connections duringclient.close(), eachconnectionCheckedInevent is immediately followed byconnectionClosed.Test verification
Verified on a local 3-node replica set:
returnbug restored → theConnectionCheckedInEventtest failsNote: this branch includes Nepomuk’s original fix commit. (Relates to #4847)
This is my first contribution to this repository.